Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Diagnostics
Imports System.Drawing
'Imports MySql.Data.MySqlClient
Imports IconPrinting.ICONPrinting
Imports Microsoft.Win32
Imports ArfaUI
Namespace ClassAll.Class
    Class ClsGeneralPrint
        Private SatuanArr As String() = {"Nol ", "Satu ", "Dua ", "Tiga ", "Empat ", "Lima ", _
         "Enam ", "Tujuh ", "Delapan ", "Sembilan "}
        Private Bil2Arr As Double() = {1, 10, 100, 1000, 1000000, 1000000000, _
         1000000000000L}
        Private BesarArr As String() = {"Satuan ", "Puluh ", "Ratus ", "Ribu ", "Juta ", "Milyar ", _
         "Triliun "}

#Region "print module"
        Public Function Fill(ByVal Nilai As Object, ByVal field As Integer, <System.Runtime.InteropServices.Optional(), System.Runtime.InteropServices.DefaultParameterValue(False)> ByVal RightAlignment As Boolean, <System.Runtime.InteropServices.Optional(), System.Runtime.InteropServices.DefaultParameterValue(False)> ByVal Angka As Boolean, <System.Runtime.InteropServices.Optional(), System.Runtime.InteropServices.DefaultParameterValue(" ")> ByVal FillWith As String, <System.Runtime.InteropServices.Optional(), System.Runtime.InteropServices.DefaultParameterValue(True)> ByVal pIsRupiah As Boolean, _
         <System.Runtime.InteropServices.Optional(), System.Runtime.InteropServices.DefaultParameterValue(False)> ByVal pIsDesimal As Boolean) As Object
            Dim functionReturnValue As Object = Nothing
            Dim Temp1 As String = Nothing
            Dim Temp2 As String = Nothing
            Dim i As Integer = 0

            If Nilai Is Nothing Then
                If Not Angka Then
                    Nilai = " "
                End If
            Else
                Nilai = Nilai.ToString().Trim()
            End If

            If Angka Then
                If Convert.ToInt64(Nilai) <= 0 Then
                    Temp1 = ""
                Else
                    If pIsRupiah Then
                        If pIsDesimal = False Then
                            Temp1 = FormatRupiah(Convert.ToDecimal(Nilai))
                        ElseIf pIsDesimal = True Then

                            Temp1 = Microsoft.VisualBasic.Strings.Left(FormatRupiah(Convert.ToDecimal(Nilai)), Microsoft.VisualBasic.Strings.Len(FormatRupiah(Convert.ToDecimal(Nilai))) - 3)
                        Else
                            Temp1 = Microsoft.VisualBasic.Strings.Left(FormatRupiah(Convert.ToDecimal(Nilai)), Microsoft.VisualBasic.Strings.Len(FormatRupiah(Convert.ToDecimal(Nilai))) - 3) & ",-"
                        End If
                    Else
                        Temp1 = Nilai.ToString()
                    End If
                End If
            Else
                Temp1 = (If(Nilai.ToString() Is Nothing, " ", Nilai.ToString()))
            End If
            Temp2 = ""
            If Microsoft.VisualBasic.Strings.Len(Temp1) < field Then
                For i = 1 To field - Microsoft.VisualBasic.Strings.Len(Temp1)
                    Temp2 = Temp2 & FillWith
                Next
            Else
                Temp1 = Microsoft.VisualBasic.Strings.Left(Temp1, field)
            End If
            If RightAlignment Then
                functionReturnValue = Temp2 & Temp1
            Else
                functionReturnValue = Temp1 & Temp2
            End If
            Return functionReturnValue
        End Function

        Public Function FormatRupiah(ByVal pRupiah As Decimal) As String
            Dim functionReturnValue As String = Nothing
            Dim sRupiah As String = Nothing
            Dim sDesimal As String = ""
            Dim iDesimal As Integer = 0
            Dim i As Integer = 0
            Dim iAwal As Integer = 0
            Dim iDigit As Integer = 0

            sRupiah = Microsoft.VisualBasic.Strings.Format(pRupiah, "#0.#0")
            iDesimal = Microsoft.VisualBasic.Strings.InStr(sRupiah, ",", CompareMethod.Binary)
            If iDesimal = 0 Then
                iDesimal = Microsoft.VisualBasic.Strings.InStr(sRupiah, ".", CompareMethod.Binary)
            End If
            If iDesimal <> 0 Then
                sDesimal = Microsoft.VisualBasic.Strings.Mid(sRupiah, iDesimal + 1, 2)
                sRupiah = Microsoft.VisualBasic.Strings.Left(sRupiah, iDesimal - 1)
            Else
            End If
            iAwal = Microsoft.VisualBasic.Strings.Len(sRupiah) Mod 3
            iDigit = Microsoft.VisualBasic.Strings.Len(sRupiah) \ 3

            If iDigit = 0 Then
                functionReturnValue = sRupiah & (If(String.IsNullOrEmpty(sDesimal), ",00", "," & sDesimal))
            Else
                functionReturnValue = Microsoft.VisualBasic.Strings.Left(sRupiah, iAwal)
                For i = 1 To (iDigit)
                    functionReturnValue = functionReturnValue & (If(iAwal = 0 And i = 1, "", ".")) & Microsoft.VisualBasic.Strings.Mid(pRupiah.ToString(), iAwal + 1 + ((i - 1) * 3), 3)
                Next
                functionReturnValue = functionReturnValue & (If(String.IsNullOrEmpty(sDesimal), ",00", "," & sDesimal))
            End If
            Return functionReturnValue
        End Function

        Public Function FillCenter(ByVal sVAL As String, ByVal iWidth As Integer, ByVal FillWith As String) As String
            Dim sReturn As String = ""
            Dim val1 As String = ""
            Dim val2 As String = ""
            Try
                Dim nDivide1 As Integer = 0
                Dim nDivide2 As Integer = 0
                Dim nDivideNumber As Integer = 0
                nDivideNumber = iWidth - sVAL.Length
                nDivide1 = Microsoft.VisualBasic.Conversion.Int(nDivideNumber \ 2)
                nDivide2 = nDivideNumber - nDivide1
                For i As Integer = 1 To nDivide1
                    val1 = val1 & FillWith
                Next
                For i As Integer = 1 To nDivide2
                    val2 = val2 & FillWith
                Next
                sReturn = val1 & sVAL & val2
            Catch ex As Exception
                sReturn = ""
            End Try
            Return sReturn
        End Function

        Public Function Terbilang(ByVal value As Double) As String
            Dim x As Int64 = Convert.ToInt64(value)


            Dim bilangan As String() = {"", "satu", "dua", "tiga", "empat", "lima", _
             "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"}

            Dim temp As String = ""



            If x < 12 Then


                temp = " " & bilangan(x)

            ElseIf x < 20 Then


                temp = Terbilang(x - 10).ToString() & " belas"

            ElseIf x < 100 Then


                temp = Terbilang(x \ 10) & " puluh" & Terbilang(x Mod 10)

            ElseIf x < 200 Then


                temp = " seratus" & Terbilang(x - 100)

            ElseIf x < 1000 Then


                temp = Terbilang(x \ 100) & " ratus" & Terbilang(x Mod 100)

            ElseIf x < 2000 Then


                temp = " seribu" & Terbilang(x - 1000)

            ElseIf x < 1000000 Then


                temp = Terbilang(x \ 1000) & " ribu" & Terbilang(x Mod 1000)

            ElseIf x < 1000000000 Then


                temp = Terbilang(x \ 1000000) & " juta" & Terbilang(x Mod 1000000)
            End If



            Return temp

        End Function

#End Region
    End Class

    Class ClsOutPutTransaksi


        Private dataprint As String = ""
        Private headertext As String = ""
        Private noantrian As Integer = 0
        Private tanggaljam As String = ""
        Private unit As String = ""

        'String sDataToPrint = "";
        Private errmsg As [String] = ""

        Private iLeftMargin As Integer = 0
        Private iTopMargin As Integer = 0
        Private sPrinterName As String = ""

        'Private condb As New NetToolMysql_v12.NetMysql
        'Private getconfig As New clsINIaccess()
        Private printer As New ClsGeneralPrint()
        Private drftPrint As New GenericPrinting()
        Private linespace As New GenericPrinting.enumLineSpace()
        'Private cReg As New RegistryHandle("bits\antrian")


        Public Sub New()
        End Sub
        Private Const GS As Byte = &H1D
        Private Const LF As Byte = &HA
        Private Const ESC As Byte = &H1B
        Private Const FS As Byte = &H1C

        Private Function selectDevice(ByVal dv As Byte) As String  '1 - printer 2 - display
            selectDevice = Chr(ESC) & "=" & Chr(dv)
        End Function

        Private Function lineFeed() As String 'print and feed line
            lineFeed = Chr(LF)
        End Function

        Private Function lineFeedN(ByVal n As Byte) As String 'print and feed n lines
            lineFeedN = Chr(ESC) & "d" & Chr(n)
        End Function

        Private Function selectMode(ByVal cFont As Byte, ByVal cEmp As Byte, ByVal cDheight As Byte, ByVal cDwidth As Byte, ByVal cUnderline As Byte, ByVal cColour As Byte) As String
            Dim cBit As Byte
            Static preColour As Byte
            'Bit positions
            '7-underline 6-reserved 5-double width 4-double height 3-emphazise 2&1-reserved 0-font A or B
            If cFont = 2 Then
                'select fontA
                cBit = cUnderline * (2 ^ 7) + 0 + cDwidth * (2 ^ 5) + cDheight * (2 ^ 4) + cEmp * (2 ^ 3) + 0 + 0 + 0 * (2 ^ 0)
                selectMode = Chr(ESC) & "!" & Chr(cBit)
                selectMode = selectMode & Chr(ESC) & "M" & Chr(2) 'font c selected
            Else
                cBit = cUnderline * (2 ^ 7) + 0 + cDwidth * (2 ^ 5) + cDheight * (2 ^ 4) + cEmp * (2 ^ 3) + 0 + 0 + cFont * (2 ^ 0)
                selectMode = Chr(ESC) & "!" & Chr(cBit)
            End If
            '0,48-colour 1    1,49-colour 2
            If preColour <> cColour Then
                selectMode = selectMode & Chr(ESC) & "r" & Chr(cColour) 'setting colour
                preColour = cColour
            End If
        End Function

        Private Function setULine(ByVal n As Byte) As String
            '0,48-turn off   1,49-turn on set at 1-dot width   2,50-turn on set at 2-dot width
            setULine = Chr(ESC) & "-" & Chr(n)
        End Function

        'Private Function setEmp(n As Byte) As String
        ''LSB of n is 0, emphasized mode is turned off.
        ''LSB of n is 1, emphasized mode is turned on.
        'setEmp = Chr(ESC) & "-" & Chr(n)
        'End Function

        'Private Function setDstrike(n As Byte) As String
        ''LSB of n is 0, double-strike mode is turned off.
        ''LSB of n is 1, double-strike mode is turned on.
        'setDstrike = Chr(ESC) & "G" & Chr(n)
        'End Function

        Private Function setFont(ByVal n As Byte) As String
            '0,48-font A 1,49-font B 2,50-font C
            setFont = Chr(ESC) & "M" & Chr(n)
        End Function

        Private Function setJust(ByVal n As Byte) As String
            '0,48-left A 1,49-centre B 2,50-right
            setJust = Chr(ESC) & "a" & Chr(n)
        End Function

        Private Function genPulse(ByVal pin As Byte) As String
            '0,48-pin 2    1,49-pin 5
            genPulse = Chr(ESC) & "p" & Chr(pin) & Chr(50) & Chr(50)
        End Function

        'Private Function setColour(n As Byte) As String
        ''0,48-colour 1    1,49-colour 2
        'setColour = Chr(ESC) & "r" & Chr(n)
        'End Function

        'Private Function setCut() As String 'modified according to Samsung Manual
        'setCut = Chr(ESC) & "m"
        'End Function

        Private Function setCut(ByVal m As Byte) As String
            '0,48-full cut    1,49-half cut
            setCut = Chr(GS) & "V" & Chr(m)
        End Function

        'Private Function setCutN(m As Byte, n As Byte) As String
        ''execute paper (cutting position + N x verticle motion unit)
        ''65-full cut    66-half cut
        'setCut = Chr(GS) & "V" & Chr(m) & Chr(n)
        'End Function

        Private Function setLogo() As String
            setLogo = Chr(FS) & Chr(112) & Chr(1) & Chr(0)
        End Function

        Private Function openDraw() As String
            '0,48-pin 2    1,49-pin 5
            openDraw = Chr(ESC) & "p" & Chr(0) & Chr(60) & Chr(120)
        End Function

        Public Sub openDrawer()
            sPrinterName = My.Settings.PrinterName
            drftPrint.PrinterName = sPrinterName
            dataprint &= openDraw()
            drftPrint.PrintData(dataprint)
        End Sub


        
#Region "Cetak Header"
        Private Sub cetakHeader()
            'Dim printdoc As New Printing.PrintDocument
            'AddHandler printdoc.PrintPage, AddressOf cetakimage
            sPrinterName = My.Settings.PrinterName
            drftPrint.PrinterName = sPrinterName
            dataprint &= setLogo()
            drftPrint.PrintData(dataprint)


        End Sub
        Private Sub cetakimage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            Dim ms As New MemoryStream(IO.File.ReadAllBytes(Application.StartupPath & "\head.jpg"))
            Dim imgbarcode As Bitmap
            imgbarcode = Image.FromStream(ms)
            Using g As Graphics = e.Graphics
                Using fnt As Font = New Font("Arial", 8)
                    Dim sX As Integer = 1
                    Dim sY As Integer = 1
                    g.DrawImage(imgbarcode, sX, sY + 15)
                End Using
            End Using
        End Sub
#End Region

#Region "Cetak Nota"
        Public Sub cetakNotaJual(ByVal dt As DataTable, ByVal kdtrans As String)
            'openDrawer()
            dataprint = String.Empty
            'cetakHeader()
            dataprint = String.Empty
            Dim iLeftMargin As Integer = 0
            If IsNumeric(My.Settings.LeftMargin) Then
                iLeftMargin = My.Settings.LeftMargin
            End If

            Dim iTopMargin As Integer = 0
            If IsNumeric(My.Settings.TopMargin) Then
                iTopMargin = My.Settings.TopMargin
            End If
            sPrinterName = My.Settings.PrinterName

            drftPrint.PrinterName = sPrinterName
            drftPrint.PrinterModel = "EPSON DFX-8000"

            drftPrint.CPIValue = GenericPrinting.enumCPI.cpi15
            drftPrint.LineSpace = GenericPrinting.enumLineSpace.seperDelapan
            drftPrint.PageLength = Convert.ToInt16(5.5 * 8)
            'PanjangKertasdlmInch * 8 / PanjangKertasdlmInch * 6;
            drftPrint.SetupPrinter()

            Dim iLoop As Integer = 0

            'While iLoop < iTopMargin
            '    dataprint = dataprint & Environment.NewLine
            '    iLoop += 1
            'End While

            tanggaljam = Now().ToString("yyyy-MMM-dd hh:mm:ss")
            Dim nama As String = ""
            Dim alamat As String = ""
            Dim notelp As String = ""
            Dim dthead As New DataTable
            Dim fax As String = ""
            If Utils.executeSP("proc_master_profil", New Object() {"select", Convert.DBNull, Convert.DBNull, Convert.DBNull, Convert.DBNull}, dthead) Then
                If dthead IsNot Nothing Then
                    If dthead.Rows.Count > 0 Then
                        nama = dthead.Rows(0)("nama")
                        alamat = dthead.Rows(0)("alamat")
                        notelp = dthead.Rows(0)("telepon")
                        fax = dthead.Rows(0)("fax")
                    End If
                End If
            End If
            'header
            'openDraw()
            dataprint &= drftPrint.getFontSequence(GenericPrinting.enumCPI.cpi15)
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter(nama, 31, " ") & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter(alamat, 31, " ") & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter(notelp, 31, " ") & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("-------------------------------", 31, " ") & Environment.NewLine
            If dt IsNot Nothing Then
                If dt.Rows.Count > 0 Then
                    dataprint &= Strings.Space(iLeftMargin) & printer.Fill("Nota Penjualan", 31, False, False, " ", False, False) & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.Fill("NoTRX    : " & kdtrans, 31, False, False, " ", False, False) & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.Fill("Tanggal  : " & dt(0)("tanggal").ToString, 31, False, False, " ", False, False) & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.Fill("Waitress  : " & dt(0)("idwaitress").ToString, 31, False, False, " ", False, False) & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.Fill("Meja No  : " & dt(0)("idtabel").ToString, 31, False, False, " ", False, False) & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("-------------------------------", 31, " ") & Environment.NewLine
                    For Each dr As DataRow In dt.Rows

                        dataprint &= Strings.Space(iLeftMargin) & printer.Fill(dr("orderno") & ". " & dr("namaitemmenu") & "(" & dr("iditemmenu") & ")", 31, False, False, " ", False, False) & Environment.NewLine
                        dataprint &= Strings.Space(iLeftMargin) & _
                        printer.Fill(dr("qty"), 4, True, True, " ", False, False) & _
                    printer.Fill(" " & dr("harga"), 13, True, True, " ", True, False) & _
                    printer.Fill(dr("totaldetail"), 14, True, True, " ", True, False) & _
                     Environment.NewLine
                    Next
                    dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("-------------------------------", 31, " ") & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & _
                                printer.Fill("SubTotal", 12, False, False, " ", False, False) & _
                            printer.Fill(dt(0)("subtotal"), 19, True, True, " ", True, False) & _
                             Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & _
                                printer.Fill("Disc", 12, False, False, " ", False, False) & _
                            printer.Fill(dt(0)("discrp"), 19, True, True, " ", True, False) & _
                             Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & _
                                printer.Fill("Total", 12, False, False, " ", False, False) & _
                            printer.Fill(dt(0)("total"), 19, True, True, " ", True, False) & _
                             Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("-------------------------------", 31, " ") & Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & _
                                printer.Fill("Bayar", 12, False, False, " ", False, False) & _
                            printer.Fill(dt(0)("bayar"), 19, True, True, " ", True, False) & _
                             Environment.NewLine
                    dataprint &= Strings.Space(iLeftMargin) & _
                                printer.Fill("Kembali", 12, False, False, " ", False, False) & _
                            printer.Fill(dt(0)("kembali"), 19, True, True, " ", True, False) & _
                             Environment.NewLine
                End If
            End If
            dataprint &= Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.Fill(tanggaljam, 31, False, False, " ", False, False) & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.Fill("Petugas : " & Session.username, 31, False, False, " ", False, False) & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("-------------------------------", 31, " ") & Environment.NewLine
            dataprint &= Strings.Space(iLeftMargin) & printer.FillCenter("*********TERIMA KASIH*********", 31, " ") & Environment.NewLine
            dataprint &= lineFeedN(7)
            dataprint &= Constants.vbFormFeed
            dataprint &= setCut(1)
            'cetakHeader()
            'drftPrint.PrintData(dataprint)
            loadtext(dataprint)
        End Sub

        

    
#End Region




        Private Sub loadtext(ByVal dataprint As [String])
            Dim tsw As TextWriter = New StreamWriter("E:\test.txt")
            tsw.WriteLine(dataprint)
            tsw.Close()
            Process.Start("E:\test.txt")
        End Sub
        Private Function pecahsplit(ByVal strtosplit As String, ByVal maxlength As Integer) As String()
            Dim strarr As String()
            Dim strset As New List(Of String)
            Dim stradd As String
            strset.Clear()
            If strtosplit = String.Empty Then
                Return strset.ToArray
                Exit Function
            End If
            strarr = strtosplit.Split(" ")
            Dim ilen As Integer = 0
            Dim r As Integer = 0
            stradd = String.Empty
            For Each s As String In strarr
                ilen += s.Length + 1
                r += 1
                If ilen < maxlength Then
                    stradd &= s & " "
                    If r = strarr.Length Then
                        strset.Add(stradd)
                    End If
                ElseIf ilen >= maxlength Then
                    strset.Add(stradd)
                    ilen = s.Length + 1
                    stradd = ""
                    stradd = s & " "
                    If r = strarr.Length Then
                        strset.Add(stradd)
                    End If
                End If

            Next
            Return strset.ToArray
        End Function


        Private Function validasikata(ByVal value As String, ByVal pecahan As String, ByVal startpecahan As Integer, ByRef startpecah As Integer) As [String]
            Dim kata As [String]() = Regex.Split(value, "\W+")
            Dim katapecah As [String]() = Regex.Split(pecahan, "\W+")
            Dim hasil As String = ""
            Dim hasilkata As New List(Of [String])()
            Dim lengthhasil As Integer = 0

            For i As Integer = 0 To kata.Length - 1

                If hasilkata.Contains(kata(i)) Then
                    Continue For
                End If

                hasilkata.Add(kata(i))
            Next




            For Each word As String In katapecah
                If hasilkata.Contains(word) Then
                    hasil &= word & " "
                Else
                    Continue For


                End If
            Next
            'foreach (string word in hasilkata)
            '{
            '    int index = pecahan.IndexOf(word);
            '    if (index != -1)
            '    {
            '        lengthhasil &= word.Length + 1;
            '        if (lengthhasil > pecahan.Length)
            '        {
            '            break;
            '        }
            '        else
            '        {
            '            hasil &= word + " ";
            '        }

            '    }
            '}

            If hasil <> pecahan Then
                If startpecahan > 0 Then
                    startpecah = startpecahan - (pecahan.Length - hasil.Length) - 1
                    pecahan = hasil
                Else
                    startpecahan = startpecahan + pecahan.Length

                    startpecah = startpecahan - Math.Abs((pecahan.Length - hasil.Length))
                    pecahan = hasil
                End If
            End If

            Return pecahan
        End Function

        Private Function stringpecah(ByVal leftmargin As Integer, ByVal awal As String, ByVal maxawal As Integer, ByVal value As String, ByVal maxlength As Integer) As [String]
            Dim NewName As [String] = ""

            Dim ketpecah As [String] = ""
            Dim startpecah As Integer = 0

            Dim baris As Integer = value.Length \ maxlength
            If baris >= 1 Then
                Dim hasil As Integer = value.Length - (maxlength * baris)
                If hasil > 0 Then
                    baris &= 1
                End If
            End If
            ketpecah = value.Substring(startpecah, maxlength)
            ketpecah = validasikata(value, ketpecah, startpecah, startpecah)
            startpecah = startpecah - maxlength

            NewName = printer.Fill(" ", leftmargin, False, False, " ", False, _
             False).ToString() & Convert.ToString(printer.Fill(awal, maxawal, False, False, " ", False, _
             False)) & ": " & Convert.ToString(printer.Fill(ketpecah, maxlength, False, False, " ", False, _
             False)) & Environment.NewLine

            baris = baris - 1

            For i As Integer = 1 To baris
                startpecah = startpecah + maxlength
                If i < baris Then
                    ketpecah = value.Substring(startpecah, maxlength)
                    ketpecah = validasikata(value, ketpecah, startpecah, startpecah)
                ElseIf i = baris Then
                    Dim lastlength As Integer = value.Length - startpecah
                    If lastlength < maxlength Then
                        ketpecah = value.Substring(startpecah, lastlength)
                    ElseIf lastlength > maxlength Then
                        ketpecah = stringpecah(0, "", 0, ketpecah, maxlength)

                    End If
                End If


                NewName &= printer.Fill(" ", leftmargin, False, False, " ", False, _
                 False).ToString() & Convert.ToString(printer.Fill(" ", maxawal + 2, False, False, " ", False, _
                 False)) & Convert.ToString(printer.Fill(ketpecah, maxlength, False, False, " ", False, _
                 False)) & Environment.NewLine
            Next
            Return NewName
        End Function


    End Class

    Class RegistryHandle
        Private sInitialKey As String
        Private reg As RegistryKey

        Public Sub New()
        End Sub
        Public Sub New(ByVal InitialKey As String)
            sInitialKey = InitialKey
            reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\" & sInitialKey, True)
        End Sub

        Public Sub SaveKey(ByVal name As String, ByVal value As String)
            If reg Is Nothing Then
                reg = Registry.CurrentUser.OpenSubKey("SOFTWARE", True)
                reg.CreateSubKey(sInitialKey)
            End If
            reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\" & sInitialKey, True)
            reg.SetValue(name, value)
        End Sub

        Public Function RetrieveKey(ByVal name As String) As [Object]
            If (reg IsNot Nothing) Then
                Return reg.GetValue(name)
            Else
                Return "null"
            End If
        End Function
    End Class
End Namespace